<?php
	include '../h5.php';
	$h5 = new h5('xq');
	$itemid = $_GET['itemid'];
	if(intval($itemid)){
		$query = 'select content,itemid,title from item where itemid = '.intval($itemid);
		$row = $h5->mysql->get_one($query);

	}
    $content = preg_replace("/<[^>]*>/", '',$row['content']);
    $content = str_replace(array("&nbsp;","&gt;","&lt;"),array("",">","<"),$content);
    $Array  = preg_split('/\。|\？|\！|\.|\?|\!/is', $content); 
    $desc = $Array[0];
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">
		<link rel="stylesheet" type="text/css" href="new_file.css?v5"/>
		<script type="text/javascript" src="../js/jquery.js" ></script>
	<title><?php echo $row['title']?></title>
	<style type="text/css">

        .tips-warp{position: absolute; width: 100%; height: 100%; background: rgba(0,0,0,.6); top: 0; left: 0; z-index: 10000; display: none; }
        .tips{ position: absolute; width: 100%; top: 0; left: 0; }
        .tips img{ width: 100%; }
		
		
	</style>
    <script src="//res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>    
    <script src="./WWeixinApi.js?v=199"></script>
</head>
<body>

	<div class="wrap">
        <div class="bg"></div>
        <div class="bigBox">
    		<div class="wrap_info">
                <div class="void"></div>

    			<div class="name"><?php echo $row['title']?></div>
    			<div class="line"><img src="images/line.png"></div>
    			<div class="content">
    				
    				<?php echo $row['content']?>
    				
    			</div>

    		</div>
        </div>
        <div class="title"><img src="images/title.png"></div>
        <div class="open1"><img src="images/open1.png"></div>
	    <div class="open2"><img src="images/open2.png"></div>
        <!-- <div class="open3"><img src="images/open3.png" alt=""></div>
        <div class="btnOpen3"></div> -->
        <div class="tips-warp">
            <div class="tips"><img src="images/tips.png"></div>
        </div>

	</div>

	<script type="text/javascript">
        wxData.title='<?php echo $row['title']?>';
        wxData.qtitle='<?php echo $row['title']?>';
        wxData.link=baseurl+'news.php?itemid='+'<?php echo $itemid?>';
        wxData.desc='<?php echo $desc?>';
        wxData.share();
		document.getElementsByTagName("html")[0].style.fontSize=window.innerWidth/750*100+"px";

		var width=750,height=1334,swidth=document.body.clientWidth,sheight=document.body.clientHeight;
	    var isWlH = swidth / sheight > width / height;
	    var scale = 1;

	    console.log(swidth,sheight);

	    init();
	    openApp()
	    function init(){

	    	var content = document.getElementsByClassName("content")[0];
	    }

	    function openApp(){
	    	var open1 = document.getElementsByClassName("open1")[0];
	    	var open2 = document.getElementsByClassName("open2")[0];
            // var btnOpen3 = document.getElementsByClassName("btnOpen3")[0];
        var tipsWarp = document.getElementsByClassName('tips-warp')[0];
	    	var url ='';

	    	open1.addEventListener("click",function(){
	    		console.log('open1');
                if(!showTips()){
	    		    //window.location.href = "cocolion://wenzhang?itemid=<?php echo $itemid ?>";
                    if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i))
                    {
                        window.location.href = "cocolion://wenzhang?itemid=<?php echo $itemid ?>";//ios app协议
                        window.setTimeout(function() {
                            window.location.href = "https://itunes.apple.com/cn/app/可可狮/id1445816354?mt=8";
                        }, 2000)
                    }
                    if(navigator.userAgent.match(/android/i))
                    {
                        window.location.href = "cocolion://wenzhang?itemid=<?php echo $itemid ?>";//android app协议
                        window.setTimeout(function() {
                            window.location.href = "http://a.app.qq.com/o/simple.jsp?pkgname=com.android.kekeshi";//android 下载地址
                        }, 2000)    
                    } 
                }

	    	})
	    	open2.addEventListener("click",function(){
	    		console.log('open2');
	    		// window.location.href = url;
                if(!showTips()){
	    		   // window.location.href = "cocolion://wenzhang?itemid=<?php echo $itemid ?>";
                    if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i))
                    {
                        window.location.href = "cocolion://wenzhang?itemid=<?php echo $itemid ?>";//ios app协议
                        window.setTimeout(function() {
                            window.location.href = "https://itunes.apple.com/cn/app/可可狮/id1445816354?mt=8";
                        }, 2000)
                    }
                    if(navigator.userAgent.match(/android/i))
                    {
                        window.location.href = "cocolion://wenzhang?itemid=<?php echo $itemid ?>";//android app协议
                        window.setTimeout(function() {
                            window.location.href = "http://a.app.qq.com/o/simple.jsp?pkgname=com.android.kekeshi";//android 下载地址
                        }, 2000)    
                    } 
                }
	    	})
	    	// btnOpen3.addEventListener("click",function(){
      //           console.log('btnOpen3');
      //            window.location.href = "https://shop202012.youzan.com/";
               
      //       })
            tipsWarp.addEventListener("click",function(){
                tipsWarp.style.display = 'none';
            });
	    }

        function showTips(){
            if(!isWeiXin()){
                return false;
            }
            var tipsWarp = document.getElementsByClassName('tips-warp')[0];
            tipsWarp.style.display = 'block';
            return true;

        }

        function isWeiXin(){
            //window.navigator.userAgent属性包含了浏览器类型、版本、操作系统类型、浏览器引擎类型等信息，这个属性可以用来判断浏览器类型
            var ua = window.navigator.userAgent.toLowerCase();
            //通过正则表达式匹配ua中是否含有MicroMessenger字符串
            if(ua.match(/MicroMessenger/i) == 'micromessenger'){
                return true;
            }else{
                return false;
            }
        }
		
function submitFn(){
    //判断浏览器
    var u = navigator.userAgent;
    if(/MicroMessenger/gi.test(u)){
       // 引导用户在浏览器中打开
        alert('请在浏览器中打开');
        return;
    }
    var d = new Date();
    var t0 = d.getTime();
    if(u.indexOf('Android') > -1 || u.indexOf('Linux') > -1){
        //Android
        if(openApp1('cocolion://wenzhang?itemid=<?php echo $itemid ?>')){
         openApp1('cocolion://wenzhang?itemid=<?php echo $itemid ?>');
        }else{
            //由于打开需要1～2秒，利用这个时间差来处理－－打开app后，返回h5页面会出现页面变成app下载页面，影响用户体验
            var delay = setInterval(function(){
                 var d = new Date();
                 var t1 = d.getTime();
                 if( t1-t0<3000 && t1-t0>2000){
                    // alert('请下载APP');
                     window.location.href = " ";
                 }
                 if(t1-t0>=3000){
                      clearInterval(delay);
                 }
            },1000); 
        }
    }else if(u.indexOf('iPhone') > -1){
        //IOS
        if(openApp1('cocolion://wenzhang?itemid=<?php echo $itemid ?>')){  
            openApp1('cocolion://wenzhang?itemid=<?php echo $itemid ?>');
        }else{
            var delay = setInterval(function(){
                var d = new Date();
                var t1 = d.getTime();
                if( t1-t0<3000 && t1-t0>2000){
                    // alert('请下载APP');
                    window.location.href = "";
                }
                if(t1-t0>=3000){
                    clearInterval(delay);
                }
            },1000);
        }
    }    
}

function openApp1(src) {
// 通过iframe的方式试图打开APP，如果能正常打开，会直接切换到APP，并自动阻止a标签的默认行为
// 否则打开a标签的href链接
     var ifr = document.createElement('iframe');
     ifr.src = src;
     ifr.style.display = 'none';
     document.body.appendChild(ifr);
     window.setTimeout(function(){
          document.body.removeChild(ifr);
     },2000);
}
	</script>
</body>
</html>
